package org.hiucung.lib_network

import okhttp3.OkHttpClient
import okhttp3.ResponseBody
import org.hiucung.lib_network.http.HttpKey
import org.hiucung.lib_network.http.HttpUrl
import org.hiucung.lib_network.impl.HttpImplService
import org.hiucung.lib_network.interceptor.HttpInterceptor
import retrofit2.Call
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory

/**
 * @title: HttpManager
 * @projectName OrangeAiVoiceApp
 * @description: TODO
 * @author Kicc
 * @date 2021/11/25 17:23
 */
object HttpManager {

    private fun getClient():OkHttpClient{
        return OkHttpClient.Builder().addInterceptor(HttpInterceptor()).build()
    }

    //天气对象
    private val retrofitWeather by lazy{
        Retrofit.Builder()
            .client(getClient())
            .baseUrl(HttpUrl.WEATHER_BASE_URL)
            .addConverterFactory(GsonConverterFactory.create())
            .build()
    }

    //天气接口
    private val apiWeather by lazy {
        retrofitWeather.create(HttpImplService::class.java)
    }

    //查询天气
    fun queryWeather(city:String):Call<ResponseBody>{
        return apiWeather.getWeather(city,HttpKey.WEATHER_KEY)
    }
}